package com.bs.modules.use.service.impl;

import com.bs.modules.use.entity.AppPowerEntity;
import com.bs.modules.use.entity.AppPriceEntity;
import com.bs.modules.use.entity.AppWaterEntity;
import com.bs.modules.use.service.AppPowerService;
import com.bs.modules.use.service.AppPriceService;
import com.bs.modules.use.service.AppWaterService;
import com.bs.modules.use.service.OrderService;
import com.bs.modules.wechat.vo.VxOrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @作者 ：lichenguang
 * @描述 ：【订单信息】
 * @创建 ：2022/4/8 21:00
 */
@Service("orderServiceImpl")
public class OrderServiceImpl implements OrderService {


  @Autowired
  private AppPowerService appPowerService;

  @Autowired
  private AppWaterService appWaterService;

  @Autowired
  private AppPriceService appPriceService;

  @Override
  public List<VxOrderVo> orderHistory(Object openid, Object status) {

    List<AppPowerEntity> powerOrders = appPowerService.findOrder(openid, status);

    List<AppWaterEntity> waterOrders = appWaterService.findOrder(openid, status);

    List<VxOrderVo> list = new ArrayList<>();
    for (AppPowerEntity powerOrder : powerOrders) {
      VxOrderVo vxOrderVo = new VxOrderVo();
      vxOrderVo.setUserId(powerOrder.getUserId());
      vxOrderVo.setId(powerOrder.getPowerId());
      vxOrderVo.setTime(powerOrder.getPowerTime());
      vxOrderVo.setStatus("1".equals(powerOrder.getPowerStatus()) ? "未缴纳" : "已缴纳");
      vxOrderVo.setCount(powerOrder.getPowerCount());
      vxOrderVo.setPayableMoney("0");
      vxOrderVo.setMoney(powerOrder.getPowerMoney());
      vxOrderVo.setPayableMoney(powerOrder.getPowerMoney());
      vxOrderVo.setPowerMoneyone(powerOrder.getPowerMoneyone());

      AppPriceEntity appPriceEntity = appPriceService.getById(powerOrder.getPowerPriceid());
      vxOrderVo.setPrice(appPriceEntity.getPowerprice());
      vxOrderVo.setPayTime(powerOrder.getPowerPayTime());
      vxOrderVo.setType("1");
      list.add(vxOrderVo);
    }

    for (AppWaterEntity waterOrder : waterOrders) {
      VxOrderVo vxOrderVo = new VxOrderVo();
      vxOrderVo.setUserId(waterOrder.getUserId());
      vxOrderVo.setId(String.valueOf(waterOrder.getWaterId()));
      vxOrderVo.setTime(waterOrder.getWaterTime());
      vxOrderVo.setStatus("1".equals(waterOrder.getWaterStatus()) ? "未缴纳" : "已缴纳");
      vxOrderVo.setCount(waterOrder.getWaterCount());
      vxOrderVo.setMoney(waterOrder.getWaterMoney());
      vxOrderVo.setPowerMoneyone(waterOrder.getWaterMoneyone());

      AppPriceEntity appPriceEntity = appPriceService.getById(waterOrder.getWaterPriceid());
      vxOrderVo.setPrice(appPriceEntity.getWaterprice());
      vxOrderVo.setPayTime(waterOrder.getWaterPayTime());
      vxOrderVo.setType("2");
      vxOrderVo.setMoney(waterOrder.getWaterMoney());

      list.add(vxOrderVo);
    }


    return list;
  }

  @Override
  public void pay(Object type, Object orderId, Object payMoney) {
    if("1".equals(type)){
      // 电费缴纳
      appPowerService.pay(orderId, payMoney);

    }else{
      // 水费缴纳
      appWaterService.pay(orderId, payMoney);
    }
  }

}
